package com.sprucetec.live.common.util;

import com.sprucetec.live.common.exceptioin.SprucetecException;
import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @program: live
 * @description: 系统共用 工具类
 * @author: Kenny
 * @create: 2020-03-19 23:14
 */
public class CommonUtils {

    // 获取邮箱前缀
    public static  String getLoginAccount(String userEmail) {
        if (StringUtils.isBlank(userEmail)) return null;
        if (userEmail.indexOf("@") == -1) {
            throw new SprucetecException("邮箱错误");
        }
        String[] split = userEmail.split("@");
        return split[0];
    }

    /**
     * 计算最晚收货时间
     * @param day
     * @return
     */
    public static String getLastReceiveDateString(String day) {
        if (StringUtils.isBlank(day)) return "";
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
        return sf.format(c.getTime());

    }


}
